﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Spark.Config.Api.DTO.Sms;
using Spark.Config.Api.Services.Abstractions;

namespace Spark.Config.Api.Controllers
{
    public class SmsController : BaseController
    {
        private readonly ISmsServices _smsService;

        public SmsController(ISmsServices smsService)
        {
            _smsService = smsService;
        }

        /// <summary>
        /// 短信发送
        /// </summary>
        /// <remarks>直接发送</remarks>
        [HttpPost]
        [AllowAnonymous]
        public IActionResult Send(SendRequest request)
        {
            _smsService.Send(request);
            return Json();
        }

        /// <summary>
        /// 通过短信模板发送
        /// </summary>
        /// <param name="request">参数: Mobile:手机号 TempID:模板ID Parameters:模板参数</param>
        [HttpPost]
        [AllowAnonymous]
        public IActionResult SendByTemp(SendByTempRequest request)
        {
            _smsService.Send(request);
            return Json();
        }

        /// <summary>
        /// 获取短信模板记录
        /// </summary>
        [HttpGet]
        public IActionResult TempList([FromQuery]SmsTempSearchRequest request)
        {
            return Json(_smsService.LoadTempList(request));
        }

        /// <summary>
        /// 获取短信发送记录
        /// </summary>
        [HttpGet]
        public IActionResult RecordList([FromQuery]SmsRecordSearchRequest request)
        {
            return Json(_smsService.LoadRecordList(request));
        }

        /// <summary>
        /// 获取短信服务商列表
        /// </summary>
        [HttpGet]
        public IActionResult ProviderList([FromQuery]SmsProviderSearchRequest request)
        {
            return Json(_smsService.LoadProviderList(request));
        }

        /// <summary>
        /// 保存短信模板
        /// </summary>
        [HttpPost]
        public IActionResult SaveTemp(SmsTempRequest request)
        {
            _smsService.SaveTemp(request);
            return Json();
        }

        /// <summary>
        ///保存/更新短信提供商
        /// </summary>
        [HttpPost]
        public IActionResult SaveProvider(SmsProviderRequest request)
        {
            _smsService.SaveProvider(request);
            return Json();
        }
    }
}